package com.ocean.tree;

public class TreeNode {
    private int value;
    private TreeNode left;
    private TreeNode right;

    TreeNode(int val) {
        this.value = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.value = val;
        this.left = left;
        this.right = right;
    }

    /**
     *      1
     *   2    3
     * 4  5  6
     *
     *
     * @return
     */
    public static TreeNode getRoot() {
        TreeNode t2 = new TreeNode(4);
        TreeNode t3 = new TreeNode(5);

        TreeNode t5 = new TreeNode(6);

        TreeNode t4 = new TreeNode(3, t5, null);

        TreeNode t1 = new TreeNode(2, t2, t3);

        TreeNode root = new TreeNode(1, t1, t4);
        return root;
    }

    /**
     * *        3
     *       1    4
     *        2  5 6
     * @return
     */
    public static TreeNode getBinarySearchRoot() {
        TreeNode t2 = new TreeNode(2);
        TreeNode t6 = new TreeNode(6);

        TreeNode t5 = new TreeNode(5);

        TreeNode t4 = new TreeNode(3, t5, t6);

        TreeNode t1 = new TreeNode(1, null, t2);

        TreeNode root = new TreeNode(3, t1, t4);
        return root;
    }

    public int getValue() {
        return value;
    }

    public TreeNode getLeft() {
        return left;
    }

    public TreeNode getRight() {
        return right;
    }

    public void setLeft(TreeNode left) {
        this.left = left;
    }

    public void setRight(TreeNode right) {
        this.right = right;
    }

    public void setValue(int value) {
        this.value = value;
    }
}
